// pages/changePassword/index.js
Page({


  data: {
    u_email: null,
    verification: null,
    verification_code: null,
  },
  mailbox_verification(e) {
    this.data.u_email = e.detail.value.u_email;
    wx.request({
      // 标题
      url: 'http://460d80b632.zicp.vip/WeChat/getMailerNum.php',
      method: "POST",
      data: {
        "u_email": this.data.u_email,
      },
      header: {
        "Content-Type": "application/x-www-form-urlencoded"
      },
      success: (res) => {
        this.data.verification_code = res.data.msg
      }
    });
  },
  security_code(e) {
    this.data.verification = e.detail.value;
    if (this.data.verification != this.data.verification_code) {
      wx.showToast({
        title: '验证码输入错误',
        icon: "error",
      });
    }
  },
  new_password(e) {
    if (this.data.verification != this.data.verification_code || this.data.verification == null) {
      wx.showToast({
        title: '验证码输入错误',
        icon: "error",
      });
      return;
    }
    wx.request({
      // 标题
      url: 'http://460d80b632.zicp.vip/WeChat/doChangePassword.php',
      method: "POST",
      data: {
        "u_email": this.data.u_email,
        "u_password": e.detail.value.u_password,
      },
      header: {
        "Content-Type": "application/x-www-form-urlencoded"
      },
      success: (res) => {
        if (res.data.success) {
          wx.reLaunch({
            url: '/pages/UserLogin/index',
          });
        } else {
          wx.showToast({
            title: '密码找回失败',
            icon: "error",
          });
        }
      }
    });

  }
})